﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Globalization;
using HomeBuyerTools.ViewModels;

namespace HomeBuyerTools.Views.Expensive
{
    public partial class TotalExpensive : PhoneApplicationPage
    {
        public TotalExpensive()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(TotalExpensive_Loaded);
            LoadPivotThemes();
            Datevisable();
        }

    
        void TotalExpensive_Loaded(object sender, RoutedEventArgs e)
        {
              Visibility darkBackgroundVisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];

              if (darkBackgroundVisibility == Visibility.Visible)
              {
                  //Theme is Dark
              }

              else
              {
                  //Theme is Light
                  txtExpensiveName.MouseEnter += txtExpensiveName_MouseEnter;
                  txtExpensiveName.MouseLeave += txtExpensiveName_MouseLeave;
                  Amount.MouseEnter += Amount_MouseEnter;
                  Amount.MouseLeave += Amount_MouseLeave;
              }
            if (App.FromDate != "2/3/2012")
            {
                FromDatepickr.Value = Convert.ToDateTime(App.FromDate);
                Datevisable();

              

            }

            if (App.Todate != "7/11/2012")
            {
                ToDatepickr.Value = Convert.ToDateTime(App.Todate);
            }
        }

        void Amount_MouseLeave(object sender, MouseEventArgs e)
        {
            Amount.Foreground = new SolidColorBrush(Colors.Black);
        }

        void Amount_MouseEnter(object sender, MouseEventArgs e)
        {
            Amount.Foreground = new SolidColorBrush(Colors.White);
        }

        void txtExpensiveName_MouseLeave(object sender, MouseEventArgs e)
        {
            txtExpensiveName.Foreground = new SolidColorBrush(Colors.Black);
        }

        void txtExpensiveName_MouseEnter(object sender, MouseEventArgs e)
        {
            txtExpensiveName.Foreground = new SolidColorBrush(Colors.White);
        }

        private void Save_click(object sender, RoutedEventArgs e)
        {
          
           // btnAdd.Visibility = Visibility = Visibility.Collapsed;
         
        }

        private void imgTitle_MouseEnter(object sender, MouseEventArgs e)
        {

        }
       
        public DateTime? Value
        {
            get;
            set;
        }

       
        private void FromDatepickr_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
        {
            try
            {
                this.FromDatepickr.Value =Convert.ToDateTime(FromDatepickr.ValueString);
                App.FromDate = FromDatepickr.ValueString;
            }
            catch (Exception ex)
            {
            }
        }
        public void Datevisable()
        {
            if (App.FromDate != "2/3/2012")
            {
                //tblExpensive.Visibility = Visibility.Visible;
                //stackExp.Visibility = Visibility.Visible;
                //tblgapExp.Visibility = Visibility.Visible;
                //tblamount.Visibility = Visibility.Visible;
                //stackAmount.Visibility = Visibility.Visible;
                //tblFormDate.Visibility = Visibility.Collapsed;
                //tblTodate.Visibility = Visibility.Collapsed;
                //ToDatepickr.Visibility = Visibility.Collapsed;
                //FromDatepickr.Visibility = Visibility.Collapsed;
                //tblPeriodTime.Visibility = Visibility.Visible;
                tblPeriodTime.Text = "Period of time  :   " + "" + App.FromDate + "    To   " + App.Todate;


            }
        }
        private void ToDatepickr_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
        {

            try
            {
                DateTime date = (DateTime)e.NewDateTime;
                this.ToDatepickr.Value = date;
                App.Todate = ToDatepickr.ValueString;
            }
            catch (Exception ex)
            {
            }
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
        
           // App.FromDate = FromDatepickr.ValueString;
           // App.Todate = ToDatepickr.ValueString;
           // tblExpensive.Visibility = Visibility.Visible;
           // stackExp.Visibility = Visibility.Visible;
           // tblgapExp.Visibility = Visibility.Visible;
           // tblamount.Visibility = Visibility.Visible;
           // stackAmount.Visibility = Visibility.Visible;
           // tblFormDate.Visibility = Visibility.Collapsed;
           // tblTodate.Visibility = Visibility.Collapsed;
           // ToDatepickr.Visibility = Visibility.Collapsed;
           // FromDatepickr.Visibility = Visibility.Collapsed;
           // tblPeriodTime.Visibility = Visibility.Visible;
           // tblPeriodTime.Text = "Period of time  :   " + "" + App.FromDate + "    To   " + App.Todate;
           // //AppBarSaveDate.IsEnabled = false;
           // //AppBarSaveData.IsEnabled = true;
           //// NavigationService.Navigate(new Uri("/Views/Result/ResultPage.xaml?sectionId=4&", UriKind.Relative));
        }
        private void LoadPivotThemes()
        {
            LayoutRoot.Background = Custom.getPivotBackground();
            
        }
        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            ToDatepickr.Value = Convert.ToDateTime(App.Todate);
            FromDatepickr.Value = Convert.ToDateTime(App.FromDate);
           // tblPeriodTime.Visibility = Visibility.Collapsed;
           // tblExpensive.Visibility = Visibility.Collapsed;
           // stackExp.Visibility = Visibility.Collapsed;
           // tblgapExp.Visibility = Visibility.Collapsed;
           // tblamount.Visibility = Visibility.Collapsed;
           // stackAmount.Visibility = Visibility.Collapsed;
           // tblFormDate.Visibility = Visibility.Visible;
           // tblTodate.Visibility = Visibility.Visible;
           // ToDatepickr.Visibility = Visibility.Visible;
           // FromDatepickr.Visibility = Visibility.Visible;
           // //btnAdd.Visibility = Visibility = Visibility.Visible;
           //// AppBarSaveDate.IsEnabled =true;
           //// AppBarSaveData.IsEnabled =false;
        }

        private void AppBarSaveData_Click(object sender, EventArgs e)
        {

            Settings g = new Settings();
            g.AddTotalExpensiveInterest(txtExpensiveName.Text, Amount.Text,Convert.ToDateTime(FromDatepickr.Value),Convert.ToDateTime(ToDatepickr.Value));
            NavigationService.Navigate(new Uri("/Views/Result/ResultPage.xaml?sectionId=4&", UriKind.Relative));
        }
 
    }
}